package com.zlx.ssm.controller;

import com.zlx.ssm.model.EmployeeInfo;
import com.zlx.ssm.service.impl.UpdateServiceImpl;
import com.zlx.ssm.vo.DateInfo;
import com.zlx.ssm.vo.ResultDateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UpdateController {

    @Autowired
    private UpdateServiceImpl updateService;

    @RequestMapping("/user/updatedele/{id}")
    public String update(@PathVariable("id") String id, Model model) {

        //根据ID查数据
        EmployeeInfo employeeInfo = updateService.selectEmployeeInfo(id);
        //隐藏域回显数据
        model.addAttribute("employeeInfo", employeeInfo);

        return "update";
    }


    @RequestMapping("/upda/updateEplmo")
    @ResponseBody
    public ResultDateVo updateEpmlo(@RequestBody DateInfo dateInfo) {

        ResultDateVo resultDateVo = new ResultDateVo();

        if (ObjectUtils.isEmpty(dateInfo)) {
            resultDateVo.setCode("-1");
            resultDateVo.setMsg("修改对象错误");
            return resultDateVo;
        }
        //调用修改语句
        int i = updateService.updateEmplo(dateInfo);

        if (i > 0) {
            resultDateVo.setCode("0");
            resultDateVo.setMsg("修改成功");
            return resultDateVo;
        }

        resultDateVo.setCode("-1");
        resultDateVo.setMsg("错误信息");
        return resultDateVo;
    }
}
